const util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageIndex: 0,
    pageCount: 0,
    id:0,
    records: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.data.id = options.id
    this.getRecords();
  },


  getRecords() {
    let that = this;
    let id = that.data.id
    util.post({
      url: 'https://groomtea.icebartech.com/api/miniApp/order/salesmanPurchaseRecords',
      data: {
        "pageIndex": that.data.pageIndex,
        "pageSize": 10,
        "id":id
      },
      success:(res)=> {
        that.data.pageIndex++;
        console.log(res);
        let records = [...that.data.records, ...res.data.bussData]
        that.setData({
          pageCount: res.data.pageCount,
          records: records
        })
      }
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let index = this.data.pageIndex;
    let count = this.data.pageCount;
    if (index < count) {
      this.getRecords();
    }
    else {
      wx.showToast({
        title: '已经到底了~',
        icon:'none'
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})